package com.olclass.web.service;

import com.olclass.web.dao.CommentRepository;
import com.olclass.web.domain.Comment;
import com.olclass.web.support.QueryParamUtil;
import com.olclass.web.support.QuerySpecification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * FileName: CollegeService.java
 * Author:   Administrator
 * Date:     2021/3/23 19:12
 * Description:
 */

@Service
@Transactional
public class CommentService {
    
    @Autowired
    CommentRepository repository;
    
    public Page<Comment> queryByFilter(String filterParam, String sortParam, int start, int limit) {
        Page<Comment> results = repository.findAll(new QuerySpecification<Comment>(filterParam),
                new PageRequest(start, limit, QueryParamUtil.parseSortParams(sortParam)));
        return results;
    }

    public void save(Comment item){
        repository.save(item);
    }

    public void delete(String id){
        repository.delete(id);
    }

    public Comment findById(String id){
        return  repository.findById(id);
    }

}